package com.wxyzz.canteenadmin.goods.goodsList.controller;

import com.github.pagehelper.PageInfo;
import com.wxyzz.canteenadmin.goods.goodsList.param.GoodsListDataParam;
import com.wxyzz.canteenadmin.goods.goodsList.param.GoodsListVueParam;
import com.wxyzz.canteenadmin.goods.goodsList.service.GoodsListService;
import com.wxyzz.canteencommon.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods/goodsList")
public class GoodsListController {
    @Autowired
    private GoodsListService goodsListService;
    //查询  展示所有的数据，分页，模糊查询
    @GetMapping("/pageGoodsList")
    public R pageGoodsList(GoodsListVueParam goodsListVueParam){
        PageInfo<GoodsListDataParam> allGoodsList = goodsListService.findAllGoodsList(goodsListVueParam);
        return  R.ok(allGoodsList);
    }
    //添加  添加商品分类信息
    @PostMapping("/addGoodsList")
    public R addGoodsList(@RequestBody GoodsListVueParam goodsListVueParam){
        goodsListService.saveGoodsList(goodsListVueParam);
        return  R.ok();
    }
    //修改  在修改前先通过id进行查询展示当前行的信息
    @GetMapping("/findGoodsListById")
    public R findGoodsListById(int id){
        GoodsListDataParam goodsListById = goodsListService.findGoodsListById(id);
        return  R.ok(goodsListById);
    }
    //修改  修改商品分类信息
    @PostMapping("/updateGoodsList")
    public R updateGoodsType(@RequestBody GoodsListVueParam goodsListVueParam){
        goodsListService.UpdateGoodsList(goodsListVueParam);
        return  R.ok();
    }
    //删除数据 根据id删除
    @GetMapping("/delGoodsList")
    public R delGoodsList(int id){
        goodsListService.deleteGoodsListById(id);
        return  R.ok();
    }
    //删除数据 批量删除
    @GetMapping("/delBatchGoodsList")
    public R delBatchGoodsList(@RequestParam List<Integer> ids){
        goodsListService.delBatchGoodsListById(ids);
        return  R.ok();
    }
}
